#!/bin/bash

# 智能对话助手启动脚本

echo "🚀 启动智能对话助手..."

# 检查Redis是否运行
echo "📡 检查Redis连接..."
if ! redis-cli ping > /dev/null 2>&1; then
    echo "❌ Redis未运行，请先启动Redis服务器："
    echo "   redis-server"
    exit 1
fi
echo "✅ Redis连接正常"

# 检查Go环境
if ! command -v go &> /dev/null; then
    echo "❌ Go未安装，请先安装Go 1.21+"
    exit 1
fi

# 安装依赖
echo "📦 安装依赖..."
go mod tidy

# 编译服务器
echo "🔨 编译服务器..."
go build -o server/server server/main.go
if [ $? -ne 0 ]; then
    echo "❌ 编译失败"
    exit 1
fi

# 启动服务器
echo "🌐 启动Web服务器..."
echo "📍 访问地址: http://localhost:8080"
echo "🛑 按 Ctrl+C 停止服务器"
echo ""

./server/server
